import React from 'react';
import {
    Button,
    Text,
    View,
    Image,
    StyleSheet,
    Dimensions,
    StatusBar,
    ActivityIndicator,
    FlatList,
    ScrollView,
    RefreshControl,
    Animated,
    TouchableHighlight,
    SectionList, TouchableOpacity
} from 'react-native';
import Swiper from 'react-native-swiper';
//引入
import ScrollableTabView, { DefaultTabBar, ScrollableTabBar } from 'react-native-scrollable-tab-view';
import DLTNewLottery from './DLTNewLottery';
import DLTHistory from './DLTHistory';
import DLTChart from './DLTChart';

import Styles from './Styles';
const { width, height } = Dimensions.get('window')

export default class DLTLottery extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            tabShow: false,
            label: ['最新开奖','走势图','开奖历史'],
        };
        this.Number = '';
        this.page = 0;
    }
    static navigationOptions = {
        title: '大乐透开奖',
        //header: null,  //隐藏顶部导航栏
        //tabBarVisible: false, // 隐藏底部导航栏
        headerStyle: {
            backgroundColor: '#d0162e',
            paddingTop: 18,
        },
        headerTintColor: '#fff',
        headerTitleStyle: {

        },
    }
    componentDidMount() {
        const { navigation } = this.props;
        this.page = navigation.getParam("page");
        this.Number = navigation.getParam("Number");

        setTimeout(() => {
            this.setState({
                tabShow: true
            });
        }, 0)
    }
    // 滑动tab
    renderScrollableTab = () => {
        let label = this.state.label
        if (this.state.tabShow) {
            return (
                <ScrollableTabView
                    style={{ paddingTop: 8 }}
                    initialPage={this.page}
                    renderTabBar={() =>
                        <ScrollableTabBar
                            style={{ height: 35 }}
                            tabStyle={{ height: 35 }}
                        />
                    }
                    tabBarBackgroundColor='#fff'
                    tabBarActiveTextColor='#b4282d'
                    tabBarInactiveTextColor='#333'
                    tabBarUnderlineStyle={Styles.tabBarUnderlines}
                >
                    {
                        label.map((item, index) => {
                            if(index == 0){
                                return <DLTNewLottery navigation={this.props.navigation} tabLabel={item} key={++index} Number={this.Number} />;
                            }
                            else if(index == 1){
                                return <DLTChart navigation={this.props.navigation} tabLabel={item} key={++index} type={index} />;
                            }
                            else if(index == 2){
                                return <DLTHistory navigation={this.props.navigation} tabLabel={item} key={++index} type={index} />;
                            }                   
                          
                        })
                    }
                </ScrollableTabView>
            )
        }
    }
    render() {
        return (
            <View style={Styles.container}>
                {this.renderScrollableTab()}
            </View>
        )
    }



}
